package com.tfd.blog.utlis;

import java.util.List;

/**
 * @param <T> 泛型
 * @author TangFD@HF
 * @since 2018-12-27 11:44
 */
public class Page<T> {
    /**
     * -- 分页参数 --
     */
    private int start = 1;
    private int pageSize = 10;
    private int pageNum = 1;
    private List<T> list;
    protected long total = 0;
    //--排序参数--//
    /**
     * 排序字段名称
     */
    private String sort;
    /**
     * 排序方向
     */
    private String order;
    private boolean autoPaging = true;

    public boolean isAutoPaging() {
        return autoPaging;
    }

    public void setAutoPaging(boolean autoPaging) {
        this.autoPaging = autoPaging;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public Page() {
    }

    public Page(int pageSize, int pageNum) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
    }

    public Page(int pageSize, int pageNum, List<T> list) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.list = list;
    }

    /**
     * 设置当前页的页号,序号从1开始,低于1时自动调整为1.
     */
    public void setStart(final int start) {
        this.start = start;

        if (start < 1) {
            this.start = 1;
        }
    }

    public int getStart() {
        return start;
    }

    /**
     * 根据pageNo和pageSize计算当前页第一条记录在总结果集中的位置,序号从1开始.
     */
    public int getFirst() {
        return (pageNum - 1) * pageSize;
    }

    public int getEnd() {
        return pageNum * pageSize;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
